const Blog = require("../schema/blog");

// 列表
const listBlog = (author, size, page) => {
    return Blog.find({ author })
        .select("-author")
        .limit(size)
        .skip((page - 1) * size);
};
// 新增
const addBlog = (blog) => {
    return Blog.create(blog);
};

// 详情
const detailBlog = (id) => {
    return Blog.findById(id)
        .select("+content +author +createdAt")
        .populate("author");
};
// 查找
const findBlog = (query) => {
    return Blog.findOne(query).select("+author");
};

// 删除
const deleteBlog = (id) => {
    return Blog.findByIdAndDelete(id);
};

module.exports = { listBlog, addBlog, detailBlog, findBlog, deleteBlog };
